package cn.iocoder.yudao.module.member.dal.mysql.job;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.controller.admin.job.vo.MemberJobExportReqVO;
import cn.iocoder.yudao.module.member.controller.admin.job.vo.MemberJobPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.job.MemberCompanyJobDO;
import cn.iocoder.yudao.module.member.dal.dataobject.job.MemberJobDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * 招聘职位 Mapper
 *
 * @author 谭万全
 */
@Mapper
public interface MemberJobMapper extends BaseMapperX<MemberJobDO> {

    default PageResult<MemberJobDO> selectPage(MemberJobPageReqVO reqVO) {

        Long comanyId= reqVO.getCompanyId();
        String ncomanyId="";
        if(reqVO.getCompanyId()!=null){
            ncomanyId=comanyId.toString();
        }
        return pageQuery(reqVO, new LambdaQueryWrapperX<MemberJobDO>()
                .eqIfPresent(MemberJobDO::getCompanyId,ncomanyId )
                .likeIfPresent(MemberJobDO::getCompanyName, reqVO.getCompanyName())
                .inIfPresent(MemberJobDO::getIndustry, reqVO.getIndustry())
                .likeIfPresent(MemberJobDO::getCity, reqVO.getCity())
                .likeIfPresent(MemberJobDO::getJobName, reqVO.getJobName())
                .likeIfPresent(MemberJobDO::getEducation, reqVO.getEducation())
                .eqIfPresent(MemberJobDO::getStatus, reqVO.getStatus())
                .likeIfPresent(MemberJobDO::getTopStatus, reqVO.getTopStatus())
                .betweenIfPresent(MemberJobDO::getPublishTime, reqVO.getBeginPublishTime(), reqVO.getEndPublishTime())
                .orderBy(MemberJobDO.class, PageParam.DEFAULT_SORTING_FIELDS)
        );
    }



    MemberJobDO getJobAll(@Param("request") Long request );

    default PageResult<MemberJobDO> getJobWaitExaminePage(MemberJobPageReqVO reqVO, List<String> statuss,List<String> educations) {
        return pageQuery(reqVO, new LambdaQueryWrapperX<MemberJobDO>()
                .eqIfPresent(MemberJobDO::getCompanyId, reqVO.getCompanyId())
                .likeIfPresent(MemberJobDO::getCompanyName, reqVO.getCompanyName())
                .likeIfPresent(MemberJobDO::getJobName, reqVO.getJobName())
                .likeIfPresent(MemberJobDO::getDepartment, reqVO.getDepartment())
                .likeIfPresent(MemberJobDO::getCity, reqVO.getCity())
                .eqIfPresent(MemberJobDO::getPhone, reqVO.getPhone())
                .eqIfPresent(MemberJobDO::getEmail, reqVO.getEmail())
                .inIfPresent(MemberJobDO::getStatus,statuss)
                .likeIfPresent(MemberJobDO::getOperation, reqVO.getOperation())
                .inLikeIfPresent(MemberJobDO::getEducation,educations)
                .likeIfPresent(MemberJobDO::getCreator, reqVO.getCreator())
                .likeIfPresent(MemberJobDO::getUpdater, reqVO.getUpdater())
                .inIfPresent(MemberJobDO::getIdentify, reqVO.getIdentify())
                .inIfPresent(MemberJobDO::getIndustry, reqVO.getIndustry())
                .eqIfPresent(MemberJobDO::getJobLanguage, reqVO.getJobLanguage())
                .betweenIfPresent(MemberJobDO::getCreateTime, reqVO.getCreateStarDate(), reqVO.getCreateEndDate())
                .orBetweenIfPresent(MemberJobDO::getLowestSalary,MemberJobDO::getHighestSalary, reqVO.getLowestSalary(),reqVO.getHighestSalary(),reqVO.getLowestSalary(),reqVO.getHighestSalary())
                .orderBy(MemberJobDO.class, PageParam.DEFAULT_SORTING_FIELDS)
        );

    }
    List<MemberJobDO> getJobWaitExaminePage1(@Param("request") MemberJobPageReqVO reqVO
            , @Param("statuss") List<String> statuss
            ,@Param("educations")List<String> educations
            ,@Param("industry")List<String> industry
            ,@Param("ids")List<Long> ids);

    List<MemberJobDO> getJobView(@Param("request") MemberJobPageReqVO reqVO );

    Integer countJobWaitExaminePage1(@Param("request") MemberJobPageReqVO reqVO, @Param("statuss") List<String> statuss,@Param("educations")List<String> educations,@Param("industry")List<String> industry);


    default List<MemberJobDO> selectList1(MemberJobPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MemberJobDO>()
                .eqIfPresent(MemberJobDO::getCompanyId, reqVO.getCompanyId())
                .eqIfPresent(MemberJobDO::getStatus, reqVO.getStatus())
                .orderBy(MemberJobDO.class, PageParam.DEFAULT_SORTING_FIELDS));
    }

    default List<MemberJobDO> selectList(MemberJobExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MemberJobDO>()
                .inIfPresent(MemberJobDO::getStatus,reqVO.getStatuss())
                .orderBy(MemberJobDO.class, PageParam.DEFAULT_SORTING_FIELDS));
    }


    List<MemberCompanyJobDO> getJobListTop2(@Param("companyId")Long companyId);

    List<MemberJobDO> getHotJob(@Param("pageSize") Integer pageSize,@Param("ids") List<Long> ids);

    List<MemberJobDO> getMemberJobPage(IPage page, @Param("request") Map<String, Object> request );

    void updateBatchRecoveryMemberJob(@Param("ids") List<Long> ids);

//    Integer countJobPage(@Param("pageReqVO")MemberJobPageReqVO pageReqVO, @Param("educations")List<String> educations);
//
//    List<MemberJobDO> getJobPage(@Param("pageReqVO")MemberJobPageReqVO pageReqVO, @Param("educations")List<String> educations);


    List<MemberJobDO> getRankingJobList(@Param("request") MemberJobPageReqVO request);
//
    void updateJobHot( @Param("id") Long id,@Param("isHot") Integer isHot );

    void updateJobFixed( @Param("id") Long id,@Param("timingStatus") Integer timingStatus,@Param("fixedTime") String fixedTime );

    void updateJobClickCount( @Param("id") Long id,@Param("clickCount") Integer clickCount );

    void updateJobNew( @Param("id") Long id,@Param("isNew") Integer isNew );

    void rankingHotJobSort(@Param("list") List<MemberJobDO> list);

    void rankingNewJobSort(@Param("list") List<MemberJobDO> list);


    List<MemberJobDO> getAllJobByIds(@Param("ids")List<Long> ids);
}
